package com.hongling.uc.ons.consumer;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AliMQConsumerListener implements MessageListener {
    private static final Logger logger = LoggerFactory.getLogger(AliMQConsumerListener.class);

    @Override
    public Action consume(Message message, ConsumeContext context) {
        String msg = "";
        try {
            //do something..
            msg = new String(message.getBody(), "UTF-8");
            logger.info("订阅消息：" + msg);
            return Action.CommitMessage;
        } catch (Exception e) {
            //消费失败
            logger.info("消费失败：" + msg);
            return Action.ReconsumeLater;
        }
    }
}